package com.liuya.db;

import java.sql.ResultSet;
import java.sql.SQLException;

public interface ResultSetReader extends java.io.Serializable {
	public Object reader(ResultSet rs, String columnName) throws SQLException;

	public Object reader(ResultSet rs, int columnIndex) throws SQLException;

	class FloatReader implements ResultSetReader {

		public Object reader(ResultSet rs, int columnIndex) throws SQLException {
			return new Float(rs.getFloat(columnIndex));
		}

		public Object reader(ResultSet rs, String columnName) throws SQLException {
			return new Float(rs.getFloat(columnName));
		}
	};

	class DoubleReader implements ResultSetReader {

		public Object reader(ResultSet rs, int columnIndex) throws SQLException {
			return new Double(rs.getDouble(columnIndex));
		}

		public Object reader(ResultSet rs, String columnName) throws SQLException {
			return new Double(rs.getDouble(columnName));
		}
	};

	class IntegerReader implements ResultSetReader {

		public Object reader(ResultSet rs, int columnIndex) throws SQLException {
			return new Integer(rs.getInt(columnIndex));
		}

		public Object reader(ResultSet rs, String columnName) throws SQLException {
			return new Integer(rs.getInt(columnName));
		}
	};

	class LongReader implements ResultSetReader {

		public Object reader(ResultSet rs, int columnIndex) throws SQLException {
			return new Long(rs.getLong(columnIndex));
		}

		public Object reader(ResultSet rs, String columnName) throws SQLException {
			return new Long(rs.getLong(columnName));
		}
	};

	class BooleanReader implements ResultSetReader {

		public Object reader(ResultSet rs, int columnIndex) throws SQLException {
			return new Boolean(rs.getBoolean(columnIndex));
		}

		public Object reader(ResultSet rs, String columnName) throws SQLException {
			return new Boolean(rs.getBoolean(columnName));
		}
	};

	class ShortReader implements ResultSetReader {

		public Object reader(ResultSet rs, int columnIndex) throws SQLException {
			return new Short(rs.getShort(columnIndex));
		}

		public Object reader(ResultSet rs, String columnName) throws SQLException {
			return new Short(rs.getShort(columnName));
		}
	};

	class JavaUtilDateReader implements ResultSetReader {

		public Object reader(ResultSet rs, int columnIndex) throws SQLException {
			return rs.getTimestamp(columnIndex);
		}

		public Object reader(ResultSet rs, String columnName) throws SQLException {
			return rs.getTimestamp(columnName);
		}
	};

	class ObjectReader implements ResultSetReader {

		public Object reader(ResultSet rs, int columnIndex) throws SQLException {
			return rs.getObject(columnIndex);
		}

		public Object reader(ResultSet rs, String columnName) throws SQLException {
			return rs.getObject(columnName);
		}
	};
}
